/**
 * 
 */
var rowNumber;
$(function(){
	   $('#withdraw_table')
		.datagrid(
				{
					url : 'admin/queryWithdrawInfo.do?pageSize=10',
					collapsible : true,
					width : '100%',
					height :'450px',
					iconCls : 'icon-user',
					fitColumns : true,
					pagination : true,
					rownumbers : true,
					singleSelect:true,
					checkOnSelect:false,
					selectOnCheck:false,
					loadMsg:'正在加载数据',
					loadFilter:function(data){
						for (var i = 0; i < data.rows.length; i++) {
							if(data.rows[i].ecmStatus==1){
								data.rows[i].ecmStatus='待提现';
							}
							if(data.rows[i].ecmStatus==2){
								data.rows[i].ecmStatus='已打款';
							}
						}
						 return data;
					},
					onClickRow: function(rowIndex, rowData) {
						rowNumber = rowIndex;
					},
					onDblClickRow :function(rowIndex,rowData){
						//layer.msg("double click");
					  },
					onLoadSuccess:function(data){
						$('#withdraw_table').datagrid('selectRow',rowNumber);
					},
					toolbar:'#toolbar',
					columns : [ [
							{
								field : 'ecmUserName',
								title : '提现人姓名',
								width : 50,
								align : 'center'
							},
							{
								field : 'ecmOpenString',
								title : '提现方式',
								width : 50,
								align : 'center'
							},
							{
								field : 'ecmAccount',
								title : '提现账号',
								width : 50,
								align : 'center'
							},
							{
								field : 'ecmTime',
								title : '申请时间',
								width : 50,
								align : 'center'
							},
							{
								field : 'ecmStatus',
								title : '提现状态',
								width : 50,
								align : 'center'
							},
							{
								field : 'ecmMoney',
								title : '提现金额',
								width : 50,
								align : 'center'
							}
						   ] ]
				});
	 //设置分页控件  
		
	var p = $('#withdraw_table').datagrid('getPager');
		$(p).pagination({
			pageSize : 10,//每页显示的记录条数，默认为10  
			pageList : [ 5, 10, 20, 30, 40, 50 ],//可以设置每页记录条数的列表  
			beforePageText : '第',//页数文本框前显示的汉字  
			afterPageText : '页    共 {pages} 页',
			displayMsg : '当前显示 {from} - {to} 条记录   共 {total} 条记录',
			onSelectPage : function(pageNumber, pageSize) {
				//layer.msg("pageNumber="+pageNumber+"pageSize="+pageSize)
				var datas = {
					'ecmStatus':$('#secmStatus').combobox('getValue'),
					'ecmAccount':$('#secmAccount').textbox('getValue'),
					'ecmUserName':$('#secmUserName').textbox('getValue'),
					currentPage : (pageNumber - 1) * pageSize,
					pageSize : pageSize
				}
				loadData(datas);
			},
			onRefresh : function(pageNumber, pageSize) {
				var datas = {
						'ecmStatus':$('#secmStatus').combobox('getValue'),
						'ecmAccount':$('#secmAccount').textbox('getValue'),
						'ecmUserName':$('#secmUserName').textbox('getValue'),
						currentPage : (pageNumber - 1) * pageSize,
						pageSize : pageSize
					}
				loadData(datas);
			}
		});
	});
	$(function(){
		var pageSize = $('#withdraw_table').datagrid('getPager').data("pagination").options.pageSize;
		var pageNumber = $('#withdraw_table').datagrid('getPager').data("pagination").options.pageNumber;
		var datas={
				currentPage : (pageNumber - 1) * pageSize,
				pageSize:pageSize
				};
		//完成提现按钮
		$("#update").bind('click',function(){
			var row = $('#withdraw_table').datagrid('getSelected');
			if(row){
				if(row.ecmStatus=='待提现'){
					layer.confirm('确定提交吗？', {
						  btn: ['确定','取消'] //按钮
						}, function(){
							$.ajax({
								url : 'admin/updateWithdrawByecmStatus.do',
								type : "POST",
								dataType : "json",
								data : {
									'ecmStatus':2,
									'ecmId':row.ecmId
								},
								success : function(param) {
									layer.msg(param.tips);
									$('#withdraw_table').datagrid('reload',datas);
								}
							});
						}, function(){
						  layer.msg('请仔细检查数据');
						});
				}else{
					layer.msg('已打款,禁止操作');
				}
			}else{
				layer.msg('请选中一行');
			}
		});
		$("#search").bind('click',function(){
			var pageSize=$('#withdraw_table').datagrid('getPager').data("pagination").options.pageSize;
			var datas = {
				'pageSize':pageSize,
				'ecmStatus':$('#secmStatus').combobox('getValue'),
				'ecmAccount':$('#secmAccount').textbox('getValue'),
				'ecmUserName':$('#secmUserName').textbox('getValue'),
			}
			loadData(datas);
		});
		$("#reset").bind('click',function(){
			$('#secmStatus').combobox('setValue','');
			$('#secmAccount').textbox('setValue','');
			$('#secmUserName').textbox('setValue','');
			var pageSize=$('#withdraw_table').datagrid('getPager').data("pagination").options.pageSize;
			var datas={
					'pageSize' : pageSize,
			}
			loadData(datas)
		});
	});
	var loadData = function(datas){
		$.ajax({
			url : 'admin/queryWithdrawInfo.do',
			type : "POST",
			dataType : "json",
			data : datas,
			success : function(param) {
				$('#withdraw_table').datagrid('loadData', param);
			}
		});
	}
